package com.ruoyi.whole.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.whole.domain.DmsDealerWholePurchase;
import com.ruoyi.whole.service.IDmsDealerWholePurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 车辆采购Controller
 * 
 * @author liuchuanfa
 * @date 2024-03-04
 */
@RestController
@RequestMapping("/whole/purchase")
public class DmsDealerWholePurchaseController extends BaseController
{
    @Autowired
    private IDmsDealerWholePurchaseService dmsDealerWholePurchaseService;

    /**
     * 查询车辆采购列表
     */
    @PreAuthorize("@ss.hasPermi('whole:purchase:list')")
    @GetMapping("/list")
    public TableDataInfo list(DmsDealerWholePurchase dmsDealerWholePurchase)
    {
        startPage();
        List<DmsDealerWholePurchase> list = dmsDealerWholePurchaseService.selectDmsDealerWholePurchaseList(dmsDealerWholePurchase);
        return getDataTable(list);
    }

    /**
     * 导出车辆采购列表
     */
    @PreAuthorize("@ss.hasPermi('whole:purchase:export')")
    @Log(title = "车辆采购", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmsDealerWholePurchase dmsDealerWholePurchase)
    {
        List<DmsDealerWholePurchase> list = dmsDealerWholePurchaseService.selectDmsDealerWholePurchaseList(dmsDealerWholePurchase);
        ExcelUtil<DmsDealerWholePurchase> util = new ExcelUtil<DmsDealerWholePurchase>(DmsDealerWholePurchase.class);
        util.exportExcel(response, list, "车辆采购数据");
    }

    /**
     * 获取车辆采购详细信息
     */
    @PreAuthorize("@ss.hasPermi('whole:purchase:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dmsDealerWholePurchaseService.selectDmsDealerWholePurchaseById(id));
    }

    /**
     * 新增车辆采购
     */
    @PreAuthorize("@ss.hasPermi('whole:purchase:add')")
    @Log(title = "车辆采购", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsDealerWholePurchase dmsDealerWholePurchase)
    {
        return toAjax(dmsDealerWholePurchaseService.insertDmsDealerWholePurchase(dmsDealerWholePurchase));
    }

    /**
     * 修改车辆采购
     */
    @PreAuthorize("@ss.hasPermi('whole:purchase:edit')")
    @Log(title = "车辆采购", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsDealerWholePurchase dmsDealerWholePurchase)
    {
        return toAjax(dmsDealerWholePurchaseService.updateDmsDealerWholePurchase(dmsDealerWholePurchase));
    }

    /**
     * 删除车辆采购
     */
    @PreAuthorize("@ss.hasPermi('whole:purchase:remove')")
    @Log(title = "车辆采购", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dmsDealerWholePurchaseService.deleteDmsDealerWholePurchaseByIds(ids));
    }

    /**
     * 订单扣款
     *
     * @param dmsDealerWholePurchase
     * @return {@link AjaxResult }
     * @author liuchuanfa
     * @since 2024/03/08
     */
    @PreAuthorize("@ss.hasPermi('whole:purchase:edit')")
    @Log(title = "订单扣款", businessType = BusinessType.UPDATE)
    @PutMapping("/purchase-deduct")
    public AjaxResult purchaseDeduct(@RequestBody DmsDealerWholePurchase dmsDealerWholePurchase){
        return toAjax(dmsDealerWholePurchaseService.purchaseDeduct(dmsDealerWholePurchase));
    }
}
